< previous page page_222 next page >

Page 222
0222-01.jpg
Figure 7.21
Program Warp demonstrates several shape-distorting transformations.
Example program Grid uses a different method to specify its transformation. When you load an image, the program displays the picture overlaid with a grid of control points. Click and drag the control points to new positions. When you click the Transform button, the program maps rectangular areas in the result picture back to the corresponding quadrilateral areas in the control points on the original image. For example, if you make a control area small, the small quadrilateral is stretched to fit the larger corresponding rectangle in the output image.
Program Grid uses bilinear interpolation to map pixels in an output rectangle back to points in the input quadrilateral. If the output pixel is near the upper-left corner of the rectangle, the input pixel is near the upper-left corner of the input quadrilateral. The code for this mapping is fairly long, and it is similar to the bilinear interpolation code shown earlier in this chapter, so it is not shown here. You can see the code in the Grid program on the CD-ROM.
Summary
Area processes modify regions in an image. Spatial filters use the values of pixels in an area to determine a pixel's output value. Although a filter may examine only a small area at one time, it can produce dramatic global effects including softening, sharpening, or embossing an image.
Geometric transformations move the pixels in an image. They can stretch, shrink, rotate, or warp an image. Chapter 9 uses similar methods to implement tweening and morphing, two techniques that allow a program to generate images for animated sequences. Chapters 12 and 13 formalize certain kinds of transformations that are useful in two- and three-dimensional graphics.

 
< previous page page_222 next page >